package com.primestone.cim.dashboardforcim.mvc;

 import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.googlecode.charts4j.Color;
import com.googlecode.charts4j.GCharts;
import com.googlecode.charts4j.PieChart;
import com.googlecode.charts4j.Slice;
import com.primestone.cim.dashboardforcim.domain.Member;
import com.primestone.cim.dashboardforcim.domain.ResMeterReadings;
import com.primestone.cim.dashboardforcim.repo.ResMeterReadingsDao;

/**
 * 
 * @author cesar.mateus
 * May 27, 2013 3:51:08 PM
 * ResMeterReadingsController.java
 * dashboardForCIM
 *
 */
@Controller
@RequestMapping(value="/")
public class ResMeterReadingsController
{
    @Autowired
    private ResMeterReadingsDao resMeterReadingsDao;
    
    //private static final String  

    /**
     * 
     * @param model
     * @return
     */
    @RequestMapping(method=RequestMethod.GET)
    public String displaySortedMembers(Model model)
    {
    	Slice s1 = Slice.newSlice(15, Color.newColor("CACACA"), "Socket 85469", "Socket 85469");
		Slice s2 = Slice.newSlice(50, Color.newColor("DF7417"), "Socket 7854", "Socket 7854");
		Slice s3 = Slice.newSlice(25, Color.newColor("951800"), "Socket 4966", "Socket 4966");
		Slice s4 = Slice.newSlice(10, Color.newColor("01A1DB"), "Socket 89636", "Socket 8966");
		
		PieChart pieChart = GCharts.newPieChart(s1, s2, s3, s4);
		pieChart.setTitle("Pie Chart", Color.BLACK, 15);
		pieChart.setSize(720, 360);
		pieChart.setThreeD(true);
		
		model.addAttribute("pieUrl", pieChart.toURLString());
    	
        //model.addAttribute("newMember", new ResMeterReadings());
        model.addAttribute("readings", this.resMeterReadingsDao.findAllOrderedByJsonResultDate());
        return "index";
    }

    /**
     * 
     * @param newMember
     * @param result
     * @param model
     * @return
     */
//    @RequestMapping(method=RequestMethod.POST)
//    public String registerNewMember(@Valid @ModelAttribute("newMember") Member newMember, BindingResult result, Model model)
//    {
//        if (!result.hasErrors()) {
//            resMeterReadingsDao.register(newMember);
//            return "redirect:/";
//        }
//        else {
//            model.addAttribute("members", resMeterReadingsDao.findAllOrderedByName());
//            return "index";
//        }
//    }
}
